package View.SistemaView;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;

import Controller.UsuarioController.UsuarioController;
import Entidade.Usuario;
import View.UsuarioView.UsuarioView;
import framework.component.field.TTextField;
import framework.mvc.GenericView;

public class LoginView extends GenericView<Usuario> {

	private static final long serialVersionUID = 118427393070590491L;
	private TTextField textUsuario;
	private JPasswordField textSenha;

	public LoginView() {
		super(new UsuarioController());
		setResizable(false);
		setTitle("Fox - Empresarial");
		setSize(new Dimension(363, 108));

		JLabel label = new JLabel("Usuario:");
		label.setFont(new Font("Verdana", Font.PLAIN, 11));

		textUsuario = new TTextField();
		textUsuario.setFont(new Font("Verdana", Font.PLAIN, 11));
		textUsuario.setText("Rafael");
		textUsuario.setColumns(10);

		JLabel label_1 = new JLabel("Senha:");
		label_1.setFont(new Font("Verdana", Font.PLAIN, 11));

		JButton button = new JButton("");
		button.setIcon(new ImageIcon("Imagens\\ok.png"));
		button.setFont(new Font("Verdana", Font.PLAIN, 11));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				UsuarioController controler = (UsuarioController) getController();
				boolean b = controler.AltenticarUsuario(textUsuario.getText(),
						textSenha.getText());
				
				if (b == true) {
					dispose();
					PrincipalView frame = new PrincipalView();
					frame.abrir();
				}
			}
		});
		button.setName("acessar");

		JButton button_1 = new JButton("");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		button_1.setIcon(new ImageIcon("Imagens\\Fechar.png"));
		button_1.setFont(new Font("Verdana", Font.PLAIN, 11));
		button_1.setName("cancelar");

		textSenha = new JPasswordField();
		textSenha.setFont(new Font("Verdana", Font.PLAIN, 11));
		textSenha.setText("123");
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(label, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
						.addComponent(textSenha, Alignment.LEADING)
						.addComponent(textUsuario, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(6)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(label)
							.addComponent(textUsuario, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
					.addGap(11)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
							.addComponent(label_1)
							.addComponent(textSenha, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
					.addGap(240))
		);
		groupLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {label, label_1});
		groupLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {button, button_1});
		getContentPane().setLayout(groupLayout);
	}
}
